<?php
/*
<a title="Umweltprämie jetzt!" href="http://www.vcd.org/umweltpraemie_jetzt.html" target="_blank"><img src="http://www.vcd.org/fileadmin/user_upload/redakteure/vcd_aktiv/mitmachen/umweltpraemie_extern.gif" title="Umweltprämie jetzt!" alt="Umweltprämie jetzt!" /></a>
*/

/**
 * Plugin vcd_umweltpraemie: Link to your vcd_umweltpraemie-Shop
 * 
 * @license    GNU
 * @author     Juergen A.Lamers <jaloma.ac@googlemail.com>
 */

if (!defined('DOKU_INC'))
	define('DOKU_INC', realpath(dirname(__FILE__) . '/../../../') . '/');
if (!defined('DOKU_PLUGIN'))
	define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
require_once (DOKU_PLUGIN . 'syntax.php');

/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */

class syntax_plugin_vcd_umweltpraemie extends DokuWiki_Syntax_Plugin {

	/**
	 * return some info
	 */
	function getInfo() {
		return array (
			'author' => 'Juergen A.Lamers',
			'email' => 'jaloma.ac@googlemail.com',
			'date' => '2009-02-24',
			'name' => 'vcd_umweltpraemie -- vcd_umweltpraemie Plugin',
			'desc' => 'Link to vcd_umweltpraemie http://www.vcd.org/umweltpraemie_jetzt.html',
			'url' => 'http://wiki.dokuwiki.org/plugin:vcd_umweltpraemie',
		);
	}

	/**
	 * What kind of syntax are we?
	 */
	function getType() {
		return 'substition';
	}

	/**
	 * What about paragraphs? (optional)
	 */
	function getPType() {
		return 'block';
	}

	/**
	 * Where to sort in?
	 */
	function getSort() {
		return 999;
	}

	/**
	 * Connect pattern to lexer
	 */
	function connectTo($mode) {
		$this->Lexer->addSpecialPattern('~~vcdumweltpraemie.*?~~', $mode, 'plugin_vcd_umweltpraemie');
	}

	/**
	 * Handle the match
	 */
	function handle($match, $state, $pos, & $handler) {
		$resultStr = '';
		$paramsArr = explode('~', $match);
		for ($i = 0; $i < count($paramsArr); $i++) {
			$paramPairArr = explode('=', $paramsArr[$i]);
			switch ($paramPairArr[0]) {
				case 'vcd_umweltpraemie' :
					break;
				case '' :
					break;
				case 'size' :
					$data['size'] = $paramPairArr[1];//htmlspecialchars($paramPairArr[1], ENT_QUOTES, 'UTF-8');
					break;
				default :
//					$resultStr .= ' ' . $paramPairArr[0] . '="' . $paramPairArr[1] . '"';
					break;
			}
		}
		return $data;
	}


	/**
	 * Create output
	 */
	function render($mode, & $renderer, $data) {
		global $conf;
		if ($mode == 'xhtml') {
			$txt = '';
			$txt .= '<a title="Umweltprämie jetzt!" href="http://www.vcd.org/umweltpraemie_jetzt.html" target="_blank">'.
			'<img src="http://www.vcd.org/fileadmin/user_upload/redakteure/vcd_aktiv/mitmachen/umweltpraemie_extern.gif" title="Umweltprämie jetzt!" alt="Umweltprämie jetzt!"';
			if (isset($data['size'])) {
				$w_h=explode('*',$data['size']);
				$txt .= ' width="'.$w_h[0].'" ';
				$txt .= ' height="'.$w_h[1].'" ';
			}
			$txt .= ' /></a>';
			$renderer->doc .= $txt;
			return true;
		}
		return false;
	}
} // Class
